const Tourist = require('../../model/tourist/Tourist')

function add(req,res){

  Tourist.find({username: req.body.username})
      .then((result)=>{
          if(result){
            console.log(result)
            if (result.length>0) {
              res.json({
                  code:0,
                  msg: '当前用户名已经注册',
                  data: result
              })
            }else{
              Tourist.create(req.body, (err,result)=>{
                console.log(err)
                if(err){
                  res.json({
                    code:0,
                    msg: '增加失败'
                })
                }else{
                  res.json({
                    code:1,
                    msg: '增加成功'
                })
                }
              })
            }
              
          }else{
              res.json({
                  code:0,
                  msg: '查询失败'
              })
          }
      })

  
  
}
module.exports = add